﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Web;

namespace NHADAT.Authentication
{
    [Serializable]
    public class UserLoginSession
    {
        public string UserLoginType { get; set; }
        public int UserId { get; set; }
        public string UserGuid { get; set; }

        public static string SerializeToBase64String(UserLoginSession userDataModel)
        {
            using (var ms = new MemoryStream())
            {
                new BinaryFormatter().Serialize(ms, userDataModel);
                ms.Seek(0, SeekOrigin.Begin);
                return Convert.ToBase64String(ms.ToArray());
            }
        }

        public static UserLoginSession DeserializeFromBase64String(String str)
        {
            using (var ms = new MemoryStream(Convert.FromBase64String(str)))
            {
                ms.Seek(0, SeekOrigin.Begin);
                return (UserLoginSession)new BinaryFormatter().Deserialize(ms);
            }
        }
    }
}